package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: ShoppingCartController
 * USER: zhang
 * DATE: 2023/5/22
 * DESCRIPTION :C端-购物车信息表现层接口
 */
@Slf4j
@RestController()
@Api(tags = "C端-购物车信息表现层")
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Resource
    private ShoppingCartService shoppingCartService;

    /**
     * 添加数据购物车
     * @param shoppingCartDTO 要添加到购物车的数据 菜品Id/菜品Id+菜品口味/套餐Id
     * @return 全局通用返回信息Bean
     */
    @ApiOperation("C端-添加商品到购物车")
    @PostMapping("/add")
    public Result insertShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.insertShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车
     * @return 全局通用返回信息Bean
     */
    @ApiOperation("C端-查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> selectShoppingCart(){
        List<ShoppingCart> shoppingCartList = shoppingCartService.selectShoppingCart();
        return Result.success(shoppingCartList);
    }

    /**
     * 清空购物车功能
     * @return 全局通用返回信息Bean
     */
    @ApiOperation("C端-清空购物车")
    @DeleteMapping("/clean")
    public Result clearShoppingCart(){
        shoppingCartService.clearShoppingCart();
        return Result.success();
    }

    /**
     * 删除购物车中的一个商品
     * @param shoppingCartDTO 要删除购物车的数据 菜品Id/菜品Id+菜品口味/套餐Id
     * @return 全局通用返回信息Bean
     */
    @ApiOperation("C端-删除购物车中的一个商品")
    @PostMapping("/sub")
    public Result deleteShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.deleteShoppingCart(shoppingCartDTO);
        return Result.success();
    }

 }
